<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use QL\QueryList;
use GuzzleHttp\Cookie\CookieJar;

/**
 * 在线HTTP访问
 * 
 */
class Http extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

  

    /**
     * 在线get🕸
     * 
     * @ApiSummary  (如果识别有问题请联系QQ496631085)
     *
     * @param string $url GET地址
     * @param string $json 返回json格式，默认假
     * 
     * @return void
     */
    public function get($url,$header=null,$cookie=null,$json=false)
    {
       
        if($url){
            if (filter_var($url, FILTER_VALIDATE_URL) !== false) {

            }else{
                $this->error('地址不正确');
            }
        }


        if(!$header){
            $headers= [
                //'Cookie'=>$_COOKIE,
            'User-Agent'    => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
            'Content-Type'  => 'application/x-www-form-urlencoded; charset=UTF-8'];
        }else{
            //分割
            $headers = $header;
        }
      

    
        $data = QueryList::get($url,null,['headers'=>$headers]);
        
        if(strlen($data->getHtml())>0){
            if(!$json){
                echo $data->getHtml();
                exit();
            }
            $this->success(strlen($data->getHtml()), $data->getHtml());
        }else{
            $this->error('访问识别失败');
        }
 
        // $post['img']=$url;
        // $post['filename'] = null;
        // $post['de_type'] = 'url';
        // $post['_token'] = $data->find('meta[name=csrf-token]')->content;

        // $ql = $data->post($geturl,$post,['headers'=>$headers2]);
        // $str = $ql->getHtml();

        // $json = json_decode($str,true);
        // if($json['status']==1){
        //     $this->success($json['info'], $json['content'][0][0]);
        // }else{
        //     $this->error('失败,请联系QQ496631085');
        // }

        
    }






    
  


   

}
